Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
hast-util-is-element
Advanced tools
The hast-util-is-element package is a utility for working with HAST (Hypertext Abstract Syntax Tree) nodes. It provides functions to check if a node is an element and optionally matches a given tag name. This is particularly useful when manipulating or inspecting HTML represented within JavaScript.
Check if a node is an element
This feature allows you to verify if a given node is an element node within a HAST structure. It's useful for filtering or processing nodes in a tree.
const isElement = require('hast-util-is-element');
const node = {type: 'element', tagName: 'div'};
console.log(isElement(node)); // Outputs: true
Check if a node is a specific element
This feature extends the basic check to allow for specification of the tag name. It's useful for finding or working with specific types of elements in a document.
const isElement = require('hast-util-is-element');
const node = {type: 'element', tagName: 'span'};
console.log(isElement(node, 'span')); // Outputs: true
This package offers a more generalized approach for checking node types in unist trees, which is a part of the broader unified ecosystem. Unlike hast-util-is-element, unist-util-is can be used with different syntax trees beyond HTML, offering greater flexibility.
Similar in utility scope within the HAST ecosystem, this package checks for the presence of properties in elements. While hast-util-is-element focuses on the type and tag name of nodes, hast-util-has-property deals with the properties of those nodes, providing a complementary functionality.
hast utility to check if a node is a (certain) element.
npm:
npm install hast-util-is-element
var is = require('hast-util-is-element')
is({type: 'text', value: 'foo'}) // => false
is({type: 'element', tagName: 'a'}, 'a') // => true
is({type: 'element', tagName: 'a'}, ['a', 'area']) // => true
isElement(node[, test[, index, parent[, context]]])
Check if the given value is a (certain) element.
node
(Node
) — Node to check.test
(Function
, string
, or Array.<Test>
, optional)
— When array
, checks if any one of the subtests pass.
When string
, checks that the element has that tag name.
When function
, see test
index
(number
, optional) — Index of node
in parent
parent
(Node
, optional) — Parent of node
context
(*
, optional) — Context object to invoke test
withboolean
— Whether test
passed and node
is an Element
.
Error
— When an incorrect test
, index
, or parent
is given.
A node
that is not a node, or not an element, does not throw.
function test(element[, index, parent])
element
(Element
) — Element to checkindex
(number?
) — Index of node
in parent
parent
(Node?
) — Parent of node
*
— The to is
given context
.
boolean?
— Whether element
matches.
isElement.convert(test)
Create a test function from test
, that can later be called with a node
,
index
, and parent
.
Useful if you’re going to test many nodes, for example when creating a utility
where something else passes a compatible test.
The created function is slightly faster because it expects valid input only. Therefore, passing invalid input, yields unexpected results.
Can also be accessed with require('hast-util-is-element/convert')
.
hast-util-is-element
does not change the syntax tree so there are no openings
for cross-site scripting (XSS) attacks.
hast-util-has-property
— check if a node has a propertyhast-util-is-body-ok-link
— check if a node is “Body OK” link elementhast-util-is-conditional-comment
— check if a node is a conditional commenthast-util-is-css-link
— check if a node is a CSS link elementhast-util-is-css-style
— check if a node is a CSS style elementhast-util-embedded
— check if a node is an embedded elementhast-util-heading
— check if a node is a heading elementhast-util-interactive
— check if a node is interactivehast-util-is-javascript
— check if a node is a JavaScript script elementhast-util-labelable
— check whether a node is labelablehast-util-phrasing
— check if a node is phrasing contenthast-util-script-supporting
— check if a node is a script-supporting elementhast-util-sectioning
— check if a node is a sectioning elementhast-util-transparent
— check if a node is a transparent elementhast-util-whitespace
— check if a node is inter-element whitespaceSee contributing.md
in syntax-tree/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
hast utility to check if a node is a (certain) element
We found that hast-util-is-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.